/*
 * Copyright (C) 2010-2011 Graz University of Technology, Austria. All Rights reserved. 
 *
 * Contact: Simone Kopeinik <simone.kopeinik@tugraz.at>
 * 	   Graz University of Technology, Knowledge Management Institute, Brückenkopfgasse 1/6, 8020 Graz 	
 * 	   <http://www.kmi.tugraz.at/>
 * 
 * This software is part of the TARGET platform developed by the
 * TARGET EC-funded project www.reachyourtarget.org
 *
 * This software is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, version 3.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * The GNU General Public License is available at <http://www.gnu.org/licenses/>.
 *
 */
package at.tugraz.kmi.css.analyzer.gapvis.basic;

import java.awt.Color;

import org.apache.commons.collections15.Transformer;

import at.tugraz.kmi.css.analyzer.CompetenceAnalyzer;
import at.tugraz.kmi.css.analyzer.UserCompetence;
import at.tugraz.kmi.css.analyzer.gapvis.GraphEdge;
import at.tugraz.kmi.css.analyzer.model.CompetenceAnalyzerModel;
import at.tugraz.kmi.css.cbkst2.prereq.structurevis.CircleLayoutConverter;

import com.google.inject.Inject;
import com.jgoodies.binding.beans.PropertyConnector;
import com.jgoodies.binding.value.ValueModel;

import edu.uci.ics.jung.algorithms.layout.DAGLayout;
import edu.uci.ics.jung.visualization.DefaultVisualizationModel;
import edu.uci.ics.jung.visualization.VisualizationModel;
import edu.uci.ics.jung.visualization.VisualizationViewer;
import edu.uci.ics.jung.visualization.control.DefaultModalGraphMouse;
import edu.uci.ics.jung.visualization.control.ModalGraphMouse.Mode;

/**
 * The panel containing the Visualisation gap competence.
 * 
 * 
 * @author Georg Öttl <georg.oettl@gmail.com>
 * 
 */
class GapProfileVis extends VisualizationViewer<UserCompetence, GraphEdge> {

	private static final long		serialVersionUID	= 1L;
	private CompetenceAnalyzerModel	presentationModel;

	@Inject
	GapProfileVis(CompetenceAnalyzerModel presMmodel) {
		super(new DefaultVisualizationModel<UserCompetence, GraphEdge>(
				new DAGLayout<UserCompetence, GraphEdge>(presMmodel.getBean()
						.getGapCompetenceProfile())));
		presentationModel = presMmodel;
		VisualizationModel<UserCompetence, GraphEdge> model = super.getModel();
		 
		getRenderContext().setVertexLabelTransformer(
				new Transformer<UserCompetence, String>() {
					@Override
					public String transform(UserCompetence input) {
						return input.getName();
					}
				});
		final DefaultModalGraphMouse<UserCompetence, Number> graphMouse = new DefaultModalGraphMouse<UserCompetence, Number>();
		graphMouse.setMode(Mode.PICKING);
		setGraphMouse(graphMouse);
		setBackground(Color.WHITE);
		initComponents();
	}

	/**
	 * Initializes the jung graph visualisation
	 */
	private void initComponents() {
		ValueModel prerequesiteGraph = presentationModel
				.getModel(CompetenceAnalyzer.PROPERTY_GAP_COMPETENCE_PROFILE);
		PropertyConnector.connectAndUpdate(new CircleLayoutConverter(
				prerequesiteGraph), this, "graphLayout");
	}

}
